/**
 * Title:        流程图特殊字段检测
 * Company:      泛微软件
 */


package checkDetail;

import general.BaseBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import weaver.conn.RecordSet;
import weaver.general.Util;



public class MatrixOperatorCheck extends BaseBean implements CheckBase  {

    public static String savedids;
    @Override
    public JSONObject checkData(HashMap dataMap) {
        setRecordSet();
        (new BaseBean()).writeLog("MatrixOperatorCheck  start");
        List resultList = new ArrayList();
        String result = resultOk;
        String sqlStr = "";
        sqlStr +=" select workflow_base.workflowname,workflow_nodebase.nodename,workflow_nodegroup.groupname, ";
        sqlStr +=" workflow_flownode.workflowid,workflow_nodegroup.nodeid,workflow_base.isbill,workflow_base.formid, ";
        sqlStr +=" workflow_groupdetail.groupid from workflow_groupdetail ";
        sqlStr +=" inner join workflow_nodegroup on workflow_groupdetail.groupid = workflow_nodegroup.id ";
        sqlStr +=" inner join workflow_groupdetail_matrix on workflow_groupdetail_matrix.groupdetailid = workflow_groupdetail.id ";
        sqlStr +=" inner join workflow_nodebase on workflow_nodebase.id = workflow_nodegroup.nodeid ";
        sqlStr +=" inner join workflow_flownode on workflow_flownode.nodeid = workflow_nodegroup.nodeid ";
        sqlStr +=" inner join workflow_base on workflow_base.id = workflow_flownode.workflowid ";
        sqlStr +=" left join workflow_matrixdetail on workflow_matrixdetail.groupdetailid = workflow_groupdetail.id ";
        sqlStr +=" where workflow_groupdetail.type = 99 ";
        sqlStr +=" and (workflow_groupdetail_matrix.value_field is null or workflow_groupdetail_matrix.value_field = 0 ";
        sqlStr +="      or workflow_matrixdetail.condition_field is null or workflow_matrixdetail.condition_field = 0 ";
        sqlStr +="      or workflow_matrixdetail.workflow_field is null or workflow_matrixdetail.workflow_field = 0) ";
        recordSet.executeSql(sqlStr);
        int cnt = 0;
        String nodeids = "";
        while(recordSet.next()){
            result = resultNeedFix;
            Map resultMap = new HashMap<String,String>();
            resultMap.put("showMessage", "路径[" + recordSet.getString("workflowname") + "]节点[" + recordSet.getString("nodename") + "]操作组[" + recordSet.getString("groupname") + "]存在问题，请修复。");
            resultMap.put("linkurl","/workflow/workflow/editoperatorgroup.jsp?ajax=1&wfid=" + recordSet.getString("workflowid") + "&nodeid=" + recordSet.getString("nodeid") + "&formid=" + recordSet.getString("formid") + "&isbill=" + recordSet.getString("isbill") + "&iscust=0&id=" + recordSet.getString("groupid"));
            resultList.add(resultMap);
        }
        (new BaseBean()).writeLog("MatrixOperatorCheck  end");
        return formatReturnJsonCheck(result, resultList, this);
    }

    @Override
    public JSONObject fixData(HashMap dataMap) {
        return checkData(new HashMap());
    }

    @Override
    public String getClassName() {
        return "矩阵作为节点操作者检测";
    }

    @Override
    public String getClassDesc() {
        return "检测设置矩阵作为节点操作者， 赋值字段没有对应表单字段。";
    }
}
